using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder2;

namespace UnityContrib.CanonicalObjectExtension
{
    /// <summary>
    /// Build key used to combine a type object with a canonical and type string name. Used by
    /// ObjectBuilder to indicate exactly what is being built.
    /// </summary>
    public struct CanonicalTypeKey : IBuildKey 
    {
        private Type type;
        private string typeName;
        private string canonicalName;

        #region IBuildKey Members

        public CanonicalTypeKey(Type type, string canonicalName) : this(type, canonicalName, null) { }

        public CanonicalTypeKey(Type type, string canonicalName, string typeName)
        {
            this.type = type;
            this.canonicalName = canonicalName;
            this.typeName = !string.IsNullOrEmpty(typeName) ? typeName : null;
        }

        public object ReplaceType(Type newType)
        {
            return new CanonicalTypeKey(newType,canonicalName, typeName);
        }

        public string CanonicalName
        {
            get { return canonicalName; }
        }

        public string Name
        {
            get {return typeName;}
        }

        public Type Type
        {
            get { return type; }
        }
        #endregion

    }
}
